#!/bin/sh
export PATH=$PATH:/volume1/@appstore/py3k/usr/local/bin:/volume1/@appstore/Git/bin
hasCommandByType(){
    if type $1 2>/dev/null;
    then
        return 1
    else
        return 0
    fi
}
echo "是否要安装 (y\n)"
read char
if [ $char = y ];
then
	echo "检测环境中"
	hasCommandByType python3
	returnVue=$?
	if [ $returnVue == 0 ] ;
		then
		echo "尚未安装python3，请前往套件中心安装
"
		echo "套件源：
http://packages.synocommunity.com/
http://spk.diablos-netzwerk.de/
https://synology.emby.media/?package_repository=360efc6e-de72-4073-b603-2bfbd7001586"
		exit 0
	fi
	hasCommandByType git
	returnVue=$?
	if [ $returnVue == 0 ] ;
	then
		echo "尚未安装Git Server，请前往套件中心安装
"
		echo "套件源：
http://packages.synocommunity.com/
http://spk.diablos-netzwerk.de/
https://synology.emby.media/?package_repository=360efc6e-de72-4073-b603-2bfbd7001586"
		exit 0
	fi
	echo "检测完毕"
	echo "基础环境"
	echo "安装setuptools"
	wget --no-check-certificate -v4 https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
	tar -zxvf setuptools-19.6.tar.gz
	cd setuptools-19.6
	python3 setup.py build
	python3 setup.py install
	echo "安装setuptools完成"
	echo "安装pip"
	wget --no-check-certificate -v4 https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
	tar -zxvf pip-8.0.2.tar.gz
	cd pip-8.0.2
	python3 setup.py build
	python3 setup.py install
	echo "安装pip完成"
	echo "安装shadowsocks"
	pip install git+https://github.com/shadowsocks/shadowsocks.git@master
	echo "安装shadowsocks完成"
	echo "请输入Ss端口(请和Frp本地端口一致):"
	read duank
	echo "请输入Ss密码:"
	read passwd
	echo "安装Frp"
	cd /root
	mkdir Sakura_Frp
	cd Sakura_Frp
	wget -N --no-check-certificate https://cdn.tcotp.cn:4443/client/Sakura_frpc_linux_arm.tar.gz
	chmod +x Sakura_frpc_linux_arm.tar.gz
	tar zxvf Sakura_frpc_linux_arm.tar.gz
	rm -rf Sakura_frpc_linux_arm.tar.gz
	chmod +x Sakura_frpc_linux_arm
	echo "安装Frp完成"
	echo "请输入Frp账号:"
	read Frpzh
	echo "请输入Frp密码:"
	read FrpPass
	echo "请输入Frp线路ID:"
	read FrpId
	nohup /root/Sakura_Frp/Sakura_frpc_linux_arm --su=$Frpzh --sp=$FrpPass --sid=$FrpId &
	echo '安装完成!'
	echo '请在群辉计划任务内添加开机执行并运行'
	echo "
sleep 60
nohup /root/Sakura_Frp/Sakura_frpc_linux_arm --su=$Frpzh --sp=$FrpPass --sid=$FrpId &
ssserver -p $duank -k $passwd -m aes-256-cfb --user nobody -d start
"
else
	exit 0
fi